package com.lagou.lagourocketmq.config;


import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class RedisLock {

    @Autowired
    private RedissonClient redissonClient;

    public Boolean lock(String lockString){


        RLock lock = redissonClient.getLock(lockString);
        lock.lock(2, TimeUnit.SECONDS);

        return true;
    }


    public Boolean  unlock(String unlockString){

        RLock lock = redissonClient.getLock(unlockString);
        lock.unlock();
        return true;


    }


}
